/**
 * Created by Chen on 2016/3/23.
 */
define(function(require, exports, module){

    var $ = require('jquery');
    require('bootstrap');
    require('bootstrap.select');
    require('jquery.layer');
    require('jquery.icheck');

    var List = require('../../util/list.js');


    exports.loadList = function(param){
        var list = new List();
        list.options = {
            template : "list-template",
            container : "list-data",
            url : $CONFIG.base_url + "/api/topic/choice/list",
            param : param
        };
        list.load(function() {
            $(".topic-details").on('click',function(){
                exports.loadList1({"id":$(this).attr("value") });
            })
        });
    };
    exports.loadList({'topic.directTeacher.id':$CONFIG.uid,"delFlag":1});

    $(".btn-search-submit").click(function(){
        var $form = $("#search-form");

        var postData = $form.serialize();
        exports.loadList(postData);
    });

    $("#list-data").on("click",".choice-pass",function(){
        var data = $.parseJSON($(this).attr("data"));
        layer.confirm('是否通过该选题？', {
            btn: ['确定','取消'], //按钮
            shade: false //不显示遮罩
        }, function(){
            var posting = $.post($CONFIG.base_url + "/api/topic/choice/pass", data);
            posting.done(function(data){
                if(data == "true"){
                    layer.msg('成功', {
                        icon:1,
                        time:1000
                    },function(){
                        window.location.href = $CONFIG.base_url + "/teacher/choice/manage";
                    });
                }
                if(data == "had_pass"){
                    layer.msg('老师你眼瞎吗？已经是通过了', {
                        icon:9
                    });
                }
                if(data == "edu_pass"){
                    layer.msg('教务已经审核通过了！', {
                        icon:9
                    });
                }
                if(data == "edu_nopass"){
                    layer.msg('教务审核没通过！', {
                        icon:9
                    });
                }
            });
        }, function(){
        });
    });

    $("#list-data").on("click",".choice-nopass",function(){
        var data = $.parseJSON($(this).attr("data"));
        layer.confirm('是否不通过该选题？', {
            btn: ['确定','取消'], //按钮
            shade: false //不显示遮罩
        }, function(){
            var posting = $.post($CONFIG.base_url + "/api/topic/choice/nopass", data);
            posting.done(function(data){
                if(data == "true"){
                    layer.msg('成功', {
                        icon:1,
                        time:1000
                    },function(){
                        window.location.href = $CONFIG.base_url + "/teacher/choice/manage";
                    });
                }
                if(data == "had_nopass"){
                    layer.msg('老师你眼瞎吗？已经是不通过了！', {
                        icon:9
                    });
                }
                if(data == "edu_pass"){
                    layer.msg('教务已经审核通过了，若想反悔请联系教务', {
                        icon:9
                    });
                }
                if(data == "edu_nopass"){
                    layer.msg('你这样做有意义吗？', {
                        icon:9
                    });
                }
            });
        }, function(){
        });
    });

    //显示详情模板
    exports.loadList1 = function(param){
        var list = new List();
        list.options = {
            template : "list-template1",
            container : "list-data1",
            url : $CONFIG.base_url + "/api/topic/choice/details",
            param : param
        };
        list.load();
    };

});
